package kuzmenkov.oip.model.dao.hibernate;

import org.springframework.dao.DataAccessException;

import java.io.Serializable;

/**
 * Interface describes accessing to any database tables
 * User: Michael Kuzmenkov
 * Date: 15.03.2009
 * Time: 21:14:08
 */
public interface GenericDao<T, PK extends Serializable> {

    /**
     * Saves a new db object into a database
     * @param newInstance
     * @return primary key
     * @throws DataAccessException
     */
    PK create(T newInstance) throws DataAccessException;

    /**
     * Extracts a db object from a database by using a primary key
     */
    T read(PK id) throws DataAccessException;

    /**
     * Saves a changed db object into a database
     * 
     */
    void update(T transientObject) throws DataAccessException;

    /**
     * Deletes a db object from a database
     * @param persistentObject
     * @throws DataAccessException
     */
    void delete(T persistentObject) throws DataAccessException;
}
